package com.huatao.auth.domain.service.impl;

import com.alibaba.fastjson.JSON;
import com.huatao.auth.comon.enums.IsDeleteFlag;
import com.huatao.auth.domain.bo.AuthRoleBO;
import com.huatao.auth.domain.convert.AuthRoleBoConverter;
import com.huatao.auth.domain.service.AuthRoleDomainService;
import com.huatao.auth.infra.basic.entity.AuthRole;
import com.huatao.auth.infra.basic.service.AuthRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {

    @Resource
    private AuthRoleService authRoleService;

    @Override
    public Boolean addRole(AuthRoleBO authRoleBO) {
        log.info("AuthRoleDomainServiceImpl addRole: {}", JSON.toJSONString(authRoleBO));
        AuthRole authRole = AuthRoleBoConverter.INSTANCE.convertRoleBoToInfra(authRoleBO);
        authRole.setIsDeleted(IsDeleteFlag.NOT_DELETED.getCode());
        int count = authRoleService.insert(authRole);
        return count > 0;
    }

    @Override
    public Boolean updateRole(AuthRoleBO authRoleBO) {
        log.info("AuthRoleDomainServiceImpl updateRole: {}", JSON.toJSONString(authRoleBO));
        AuthRole authRole = AuthRoleBoConverter.INSTANCE.convertRoleBoToInfra(authRoleBO);
        int count = authRoleService.update(authRole);
        return count > 0;
    }

    @Override
    public Boolean deleteRole(AuthRoleBO authRoleBO) {
        log.info("AuthRoleDomainServiceImpl deleteRole: {}", JSON.toJSONString(authRoleBO));
        AuthRole authRole = AuthRoleBoConverter.INSTANCE.convertRoleBoToInfra(authRoleBO);
        authRole.setIsDeleted(IsDeleteFlag.DELETED.getCode());
        int count = authRoleService.update(authRole);
        return count > 0;
    }
}
